/**
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file. 
 *
 * @File name:  AddTSystemUserAction.java   添加【系统用户信息:T_SYSTEM_USER】
 * @Create on:  2012-06-25 21:11:276
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */

package com.boho.ecp.manage.user.action;

import java.sql.Connection;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.MessageService;

import com.boho.ecp.constant.User;
import com.boho.ecp.po.TSystemUserPO;
import com.boho.ecp.util.MD5Digester;

public class AddTSystemUserAction extends ActionImp {
	private TSystemUserPO tSystemUserPO = new TSystemUserPO();
	private Connection con = null;

	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("BOHO_COMMON_1001", MessageService.getMessage("BOHO_COMMON_1001"), "【系统用户信息】", ex);
		}
	}

	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		POUtils.insert(con, tSystemUserPO, false);
		return 1;
	}

	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		Integer createBy = (Integer)atx.getSessionValue(User.USER_NO_SESSION);
		tSystemUserPO.setLoginName(atx.getStringValue("LOGIN_NAME"));
		tSystemUserPO.setPassword(MD5Digester.digest(atx.getStringValue("PASSWORD")));
		tSystemUserPO.setRealName(atx.getStringValue("REAL_NAME"));
		tSystemUserPO.setMobile(atx.getStringValue("MOBILE"));
		tSystemUserPO.setEmail(atx.getStringValue("EMAIL"));
		tSystemUserPO.setRemark(atx.getStringValue("REMARK"));
		tSystemUserPO.setCreateBy(createBy.toString());
		tSystemUserPO.setCreateDate(new java.util.Date());
		return 1;
	}
}
